home *** CD-ROM | disk | FTP | other *** search
/ Cracking 1 / Cracking I..iso / Tools / Ostatní / aPLib v0.26b / src / nasm / depack.nas next >
Encoding:
Text File  |  2001-12-15  |  2.0 KB  |  118 lines

  1. ;;
  2. ;; aPLib compression library  -  the smaller the better :)
  3. ;;
  4. ;; NASM assembler depacker
  5. ;;
  6. ;; Copyright (c) 1998-2000 by Joergen Ibsen / Jibz
  7. ;; All Rights Reserved
  8. ;;
  9. ;; -> NASM by Archee/CoNTRACT (soltesz@hotmail.com)
  10. ;;
  11.  
  12. section .text use32
  13.  
  14. global _aP_depack_asm
  15.  
  16. _aP_depack_asm:
  17.     pushad
  18.  
  19.     mov    esi, [esp + 36]    ; C calling convention
  20.     mov    edi, [esp + 40]
  21.  
  22.     cld
  23.     mov    dl, 80h
  24.  
  25. literal:
  26.     movsb
  27. nexttag:
  28.     call   getbit
  29.     jnc    literal
  30.  
  31.     xor    ecx, ecx
  32.     call   getbit
  33.     jnc    codepair
  34.     xor    eax, eax
  35.     call   getbit
  36.     jnc    shortmatch
  37.     inc    ecx
  38.     mov    al, 10h
  39. getmorebits:
  40.     call   getbit
  41.     adc    al, al
  42.     jnc    getmorebits
  43.     jnz    domatch
  44.     stosb
  45.     jmp    short nexttag
  46. codepair:
  47.     call   getgamma_no_ecx
  48.     dec    ecx
  49.     loop   normalcodepair
  50.     call   getgamma
  51.     jmp    short domatch_lastpos
  52.  
  53. shortmatch:
  54.     lodsb
  55.     shr    eax, 1
  56.     jz     donedepacking
  57.     adc    ecx, ecx
  58.     jmp    short domatch_with_2inc
  59.  
  60. normalcodepair:
  61.     xchg   eax, ecx
  62.     dec    eax
  63.     shl    eax, 8
  64.     lodsb
  65.     call   getgamma
  66.     cmp    eax, 32000
  67.     jae    domatch_with_2inc
  68.     cmp    ah, 5
  69.     jae    domatch_with_inc
  70.     cmp    eax, BYTE 7fh
  71.     ja     domatch_new_lastpos
  72.  
  73. domatch_with_2inc:
  74.     inc    ecx
  75.  
  76. domatch_with_inc:
  77.     inc    ecx
  78.  
  79. domatch_new_lastpos:
  80.     xchg   eax, ebp
  81. domatch_lastpos:
  82.     mov    eax, ebp
  83.  
  84. domatch:
  85.     push   esi
  86.     mov    esi, edi
  87.     sub    esi, eax
  88.     rep    movsb
  89.     pop    esi
  90.     jmp    short nexttag
  91.  
  92. getbit:
  93.     add     dl, dl
  94.     jnz     stillbitsleft
  95.     mov     dl, [esi]
  96.     inc     esi
  97.     adc     dl, dl
  98. stillbitsleft:
  99.     ret
  100.  
  101. getgamma:
  102.     xor    ecx, ecx
  103. getgamma_no_ecx:
  104.     inc    ecx
  105. getgammaloop:
  106.     call   getbit
  107.     adc    ecx, ecx
  108.     call   getbit
  109.     jc     getgammaloop
  110.     ret
  111.  
  112. donedepacking:
  113.     sub    edi, [esp + 40]
  114.     mov    [esp + 28], edi    ; return unpacked length in eax
  115.  
  116.     popad
  117.     ret
  118.